package com.hwadee.backend.entity.HealthRecord;

import lombok.Getter;
import lombok.Setter;

import java.sql.Date;

@Setter
@Getter
public class FamilyHistory extends HealthRecord {
    // 病人姓名
    private String patientName;
    // 疾病名称
    private String diseaseName;
    // 亲属关系
    private String relationship;
    // 发病频次
    private String onsetFrequency;
    // 备注
    private String remarks;

    public FamilyHistory() {
    }

    public FamilyHistory(int recordId, Date recordDate, String recordType, String detail) {
        super(recordId, recordDate, recordType, detail);
        splitDetail(detail);
        super.setDetail(null); // 将 detail 置为空值
    }

    /**
     * 从 detail 字符串中解析病人姓名、疾病名称、亲属关系、发病频次和备注
     * @param detail 包含病人姓名、疾病名称、亲属关系、发病频次和备注的字符串，用 | 分隔
     */
    private void splitDetail(String detail) {
        String[] parts = detail.split("\\|");
        if (parts.length >= 1) {
            this.patientName = parts[0];
        }
        if (parts.length >= 2) {
            this.diseaseName = parts[1];
        }
        if (parts.length >= 3) {
            this.relationship = parts[2];
        }
        if (parts.length >= 4) {
            this.onsetFrequency = parts[3];
        }
        if (parts.length >= 5) {
            this.remarks = parts[4];
        }
    }

}